﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.ComponentModel;
using VIBlend.WPF.Controls;

namespace AnonsaiWPF.CSharp.DataGridViewDemos
{
    [Category("VIBlend.WPF.Examples")]
    public partial class CheckBoxEditor: Window, IWindow
    {
        #region IWindow Members

        public void DetachContent()
        {
            RemoveLogicalChild(Content);
        }

        public Grid Root
        {
            get
            {
                return this.LayoutRoot;
            }
        }
        #endregion

        public void SetTheme()
        {
            dataGrid1.FontFamily = new FontFamily("Tahoma");
        }
  
        public CheckBoxEditor()
        {   
            InitializeComponent();
            PrepareGridData();

            // Binds the data grid to a list of books.
            dataGrid1.ItemsSource = listBooks;

            // Disables columns resizing.
            dataGrid1.ColumnsHierarchy.AllowResize = false;
        }

        protected override void OnClosing(CancelEventArgs e)
        {
            this.listBooks.Clear();
            this.listBooks = null;

            base.OnClosing(e);
            this.dataGrid1.Dispose();
            this.dataGrid1 = null;
        }

        public class Book
        {
            public Book(string title, string isbn, string author, bool inStock)
            {
                this.BookTitle = title;
                this.ISBN = isbn;
                this.Author = author;
                this.IsInStock = inStock;
            }

            public string BookTitle { get; set; }
            public string ISBN { get; set; }
            public string Author { get; set; }
            public bool IsInStock { get; set; }
        }

        public List<Book> listBooks = new List<Book>();

        private void PrepareGridData()
        {
            Random rand = new Random();
            for (int i = 0; i < 1000; i++)
            {
                int val = rand.Next();
                listBooks.Add(new Book("Title " + i, "ISBN " + i, "Author " + i, val % 2 == 0));
            }
        }
    }

 }
